# -*- coding: utf-8 -*-

"""
@Datetime: 2019/5/21
@Author: Zhang Yafei
@Description: 函数参数
"""
""" 函数定义 """


""" 必选参数 """
def rect_area(width, height):  # 形参列表
    area  = width * height
    return area

def print_area(width, height):
    area = width * height
    print(f'{width} × {height} 长方形的面积为：{area}')

""" 调用函数 """
# 使用位置参数
r_area = rect_area(320, 480)  # 实参列表，顺序必须于形参一致
print(f'320 × 480 长方形的面积为：{r_area}')
# 使用关键词参数
r_area = rect_area(width=320, height=480)  # 实参列表，顺序必须于形参一致
print(f'320 × 480 长方形的面积为：{r_area}')
r_area = rect_area(width=320, height=480)  # 实参列表，顺序必须于形参一致
print(f'320 × 480 长方形的面积为：{r_area}')


""" 可选参数 """
def make_coffee(name='卡布奇诺'):
    return f'制作一杯{name}咖啡'

coffee1 = make_coffee('拿铁')
coffee2 = make_coffee()
print(coffee1)
print(coffee2)


""" 不定长参数 """
def sum_of_nums(*numbers):
    total = 0.0
    for num in numbers:
        total += num
    return total

print(sum_of_nums(100.0, 25.4, 23.6))  # 149.0
print(sum_of_nums(30.0, 75.0))         # 105.0
print(sum_of_nums(20.0))               # 20.0
print(sum_of_nums())                   # 0.0

def show_info(**info):
    print('show_info'.center(20, '-'))
    for key, value in info.items():
        print(f'{key} - {value}')


show_info(name='Marry', age=18, sex=True)  # 多个参数被组装成字典info，字典的键是name、age, sex，字典的值是'Marry',18, True
show_info(student_name='Tony', student_no='2020110003')  # 多个参数被组装成字典info，字典的键是student_name、student_no，字典的值是'2020110003'

def sum_of_nums2(*args, **kwargs):
    total = 0
    for num in args:
        total += num
    for num in kwargs.values():
        total += num
    return total

print(sum_of_nums2())                  # 0
print(sum_of_nums2(1, 2, 3))           # 6
print(sum_of_nums2(a=1, b=2, c=3))     # 6
print(sum_of_nums2(1, 2, c=3, d=4))    # 10
"""
-----show_info------
name - Marry
age - 18
sex - True
-----show_info------
student_name - Tony
student_no - 2020110003
"""


# def sum_2_nums(a, b):
#     result = a + b
#     print("%d + %d = %d" % (a, b, result))
#
#
# num1 = int(input("请输入第一个数字: "))
# num2 = int(input("请输入第二个数字: "))
#
# # 调用函数
# sum_2_nums(num1, num2)